const Router = require("koa-router");
const requireDir = require("require-directory");
const render = require('koa-art-template');
const koaBody = require('koa-body')
const path = require("path");
const static = require("koa-static");
function initProject(app) {
    app.use(koaBody({
        multipart: true,
        formidable: {
            maxFileSize: 200 * 1024 * 1024,
            keepExtensions: true
        }
    }))
    requireDir(module, "../routers", { visit: loadRoutes })
    render(app, {
        root: path.join(process.cwd(), 'pages'),
        extname: '.html',
        debug: process.env.NODE_ENV !== 'production'
    });
    function loadRoutes(obj) {
        console.log(obj instanceof Router);
        if (obj instanceof Router) {
            app.use(obj.routes())
        }
    }
    app.use(static(path.join(process.cwd(), "static")))
    app.use(async (ctx, next) => {
        ctx.set("Access-Control-Allow-Origin", "*");
        await next();
    })
}
module.exports = initProject